// pages/onlineMall/onlineMall.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
      // 基础导航列表（对应截图可见的）

    menu: [
        { icon: "/images/hot.png", text: "当季爆款", type: "hot",url: "/pages/hot/hot"},
        { icon: "/images/program.png", text: "节目同款", type: "program",url: "/pages/program/program" },
        { icon: "/images/cart1.png", text: "购物车", type: "cart",url: "/pages/cart/cart"  },
        
    ],
    navList: [
        { title: "首页" },
        { title: "食品" },
        { title: "鞋包" },
        { title: "服饰" },
        { title: "水果" },
        { title: "百货" },
        { title: "医药" },
        { title: "电器" },
        { title: "家纺" },
        { title: "运动" },
        { title: "家具" }
      ],
      // 更多导航列表（可扩展老年相关其他分类）
      moreNavList: [
        { title: "康复护理" },
        { title: "老年服饰" }
      ],
      productList: [
        { id: 1, title: '老上海鲜得来排骨年糕', price: '118', originalPrice: '135', image: 'https://n.sinaimg.cn/sinacn10101/208/w640h368/20190203/0f40-hsmkfyn9120971.png' },
        { id: 2, title: '巴湖六月黄大闸蟹', price: '99', originalPrice: '129', image: 'https://ts1.tc.mm.bing.net/th/id/OIP-C.ZcCX47AVPQ6dLJSp1yZjbgHaE7?rs=1&pid=ImgDetMain&o=7&rm=3' },
        { id: 3, title: '豫园制造薄皮鲜肉小笼包', price: '59.9', originalPrice: '129', image: 'https://aimg8.dlssyht.cn/u/2011304/ueditor/image/1006/2011304/1683099058693241.jpg' },
        { id: 4, title: '老上海风味香糟六拼', price: '79.9', originalPrice: '99', image: 'https://ts4.tc.mm.bing.net/th/id/OIP-C.twaMnF3Cg0eEMrN2OsJP5AHaIB?rs=1&pid=ImgDetMain&o=7&rm=3' },
      ],
      goodsList: [
        { id: 1, title: '上海特产鲜肉月饼', price: '49.9', originalPrice: '69.9', image: 'https://ts2.tc.mm.bing.net/th/id/OIP-C.RuntdhHWOM2q-DHMBLtzEQHaLG?rs=1&pid=ImgDetMain&o=7&rm=3' },
        { id: 2, title: '崇明岛生态大米', price: '68', originalPrice: '88', image: 'https://img.alicdn.com/bao/uploaded/i3/2208334171994/O1CN01R6E3Xq1QbIXkaWEX3_!!0-item_pic.jpg' },
        {
            id: 3,
            title: "无糖高钙燕麦片",
            price: "49.9",
            originalPrice: "69.9",
            image: "https://ts2.tc.mm.bing.net/th/id/OIP-C.0dJgkQfHt9U5pyMvAH3KQwHaHa?rs=1&pid=ImgDetMain&o=7&rm=3"
          },
          {
            id: 4,
            title: "益生菌低脂奶粉",
            price: "78.0",
            originalPrice: "98.0",
            image: "https://ts2.tc.mm.bing.net/th/id/OIP-C.jDMYpp6_X3WXWVoOmKMpWQHaIz?rs=1&pid=ImgDetMain&o=7&rm=3"
          },
      ],
      weeknew: [
        { id: 1, title: '上海特产鲜肉月饼', price: '49.9', originalPrice: '69.9', image: 'https://ts2.tc.mm.bing.net/th/id/OIP-C.RuntdhHWOM2q-DHMBLtzEQHaLG?rs=1&pid=ImgDetMain&o=7&rm=3' },
        { id: 2, title: '木糖醇藕粉羹', price: '68', originalPrice: '88', image: 'https://statics.vmcyun.com/5a/94/9da2d5bb957b.jpg!l?61599_OW800_OH800' },
        { id: 3, title: '益生菌低脂奶粉', price: '129', originalPrice: '159', image: 'https://ts1.tc.mm.bing.net/th/id/OIP-C.Y_U6CQRLPzzjfQW0KcNJPAHaHa?rs=1&pid=ImgDetMain&o=7&rm=3' },
        { id: 4, title: '黑豆核桃芝麻糊', price: '159', originalPrice: '199', image: 'https://ts1.tc.mm.bing.net/th/id/OIP-C.Kp5W_62axVDcUkix9ENJTQHaHa?rs=1&pid=ImgDetMain&o=7&rm=3' }
      ],
      new: [
        { id: 1, title: '上海特产鲜肉月饼', price: '49.9', originalPrice: '69.9', image: 'https://ts2.tc.mm.bing.net/th/id/OIP-C.RuntdhHWOM2q-DHMBLtzEQHaLG?rs=1&pid=ImgDetMain&o=7&rm=3' },
        { id: 2, title: '木糖醇藕粉羹', price: '68', originalPrice: '88', image: 'https://statics.vmcyun.com/5a/94/9da2d5bb957b.jpg!l?61599_OW800_OH800' },
        { id: 3, title: '益生菌低脂奶粉', price: '129', originalPrice: '159', image: 'https://ts1.tc.mm.bing.net/th/id/OIP-C.Y_U6CQRLPzzjfQW0KcNJPAHaHa?rs=1&pid=ImgDetMain&o=7&rm=3' },
        { id: 4, title: '黑豆核桃芝麻糊', price: '159', originalPrice: '199', image: 'https://ts1.tc.mm.bing.net/th/id/OIP-C.Kp5W_62axVDcUkix9ENJTQHaHa?rs=1&pid=ImgDetMain&o=7&rm=3' },
        { id: 5, title: '益生菌低脂奶粉', price: '129', originalPrice: '159', image: 'https://ts1.tc.mm.bing.net/th/id/OIP-C.Y_U6CQRLPzzjfQW0KcNJPAHaHa?rs=1&pid=ImgDetMain&o=7&rm=3' },
        { id: 6, title: '黑豆核桃芝麻糊', price: '159', originalPrice: '199', image: 'https://ts1.tc.mm.bing.net/th/id/OIP-C.Kp5W_62axVDcUkix9ENJTQHaHa?rs=1&pid=ImgDetMain&o=7&rm=3' }

      ],
      newList: [
        { id: 1, title: '老上海鲜得来排骨年糕', price: '118', originalPrice: '135', image: 'https://n.sinaimg.cn/sinacn10101/208/w640h368/20190203/0f40-hsmkfyn9120971.png' },
        { id: 2, title: '巴湖六月黄大闸蟹', price: '99', originalPrice: '129', image: 'https://ts1.tc.mm.bing.net/th/id/OIP-C.ZcCX47AVPQ6dLJSp1yZjbgHaE7?rs=1&pid=ImgDetMain&o=7&rm=3' },
        { id: 3, title: '豫园制造薄皮鲜肉小笼包', price: '59.9', originalPrice: '129', image: 'https://aimg8.dlssyht.cn/u/2011304/ueditor/image/1006/2011304/1683099058693241.jpg' },
        { id: 4, title: '老上海风味香糟六拼', price: '79.9', originalPrice: '99', image: 'https://ts4.tc.mm.bing.net/th/id/OIP-C.twaMnF3Cg0eEMrN2OsJP5AHaIB?rs=1&pid=ImgDetMain&o=7&rm=3' },
        { id: 3, title: '豫园制造薄皮鲜肉小笼包', price: '59.9', originalPrice: '129', image: 'https://aimg8.dlssyht.cn/u/2011304/ueditor/image/1006/2011304/1683099058693241.jpg' },
        { id: 4, title: '老上海风味香糟六拼', price: '79.9', originalPrice: '99', image: 'https://ts4.tc.mm.bing.net/th/id/OIP-C.twaMnF3Cg0eEMrN2OsJP5AHaIB?rs=1&pid=ImgDetMain&o=7&rm=3' }
      ],

      currentTab: 0, // 当前选中的导航索引
      showMoreNav: false ,// 是否显示更多导航
    products: {
      '精选推荐': [
        {
          "id": 101,
          "name": "无糖高钙燕麦片",
          "price": "49.9",
          "originalPrice": "69.9",
          "image": "https://picsum.photos/seed/elder-oats/400/300"
        },
        {
          "id": 102,
          "name": "益生菌低脂奶粉",
          "price": "78.0",
          "originalPrice": "98.0",
          "image": "https://picsum.photos/seed/elder-milk/400/300"
        },
        {
          "id": 103,
          "name": "黑豆核桃芝麻糊",
          "price": "42.9",
          "originalPrice": "59.9",
          "image": "https://picsum.photos/seed/elder-sesame/400/300"
        },
        {
          "id": 104,
          "name": "高纤无糖苏打饼",
          "price": "29.9",
          "originalPrice": "39.9",
          "image": "https://picsum.photos/seed/elder-biscuit/400/300"
        },
        {
          "id": 105,
          "name": "低盐即食燕麦粥",
          "price": "45.9",
          "originalPrice": "65.9",
          "image": "https://picsum.photos/seed/elder-porridge/400/300"
        },
        {
          "id": 106,
          "name": "木糖醇藕粉羹",
          "price": "32.8",
          "originalPrice": "45.8",
          "image": "https://picsum.photos/seed/elder-lotus/400/300"
        }
      ],
      '健康食品': [
        { id: 1, name: '有机无糖燕麦片', price: '59.9', originalPrice: '79.9', image: 'https://picsum.photos/seed/food1/400/300' },
        { id: 2, name: '高钙低脂牛奶', price: '68', originalPrice: '88', image: 'https://picsum.photos/seed/food2/400/300' },
        { id: 3, name: '黑芝麻核桃粉', price: '45.9', originalPrice: '65.9', image: 'https://picsum.photos/seed/food3/400/300' },
        { id: 4, name: '无糖杂粮饼干', price: '32.8', originalPrice: '42.8', image: 'https://picsum.photos/seed/food4/400/300' },
        { id: 5, name: '低脂燕麦片', price: '49.9', originalPrice: '69.9', image: 'https://picsum.photos/seed/food5/400/300' },
        { id: 6, name: '低糖藕粉', price: '35.9', originalPrice: '45.9', image: 'https://picsum.photos/seed/food6/400/300' }
      ],
      '舒适服饰': [
        { id: 1, name: '中老年保暖内衣', price: '129', originalPrice: '159', image: 'https://picsum.photos/seed/clothing1/400/300' },
        { id: 2, name: '老年防滑健步鞋', price: '159', originalPrice: '199', image: 'https://picsum.photos/seed/clothing2/400/300' },
        { id: 3, name: '宽松休闲外套', price: '199', originalPrice: '239', image: 'https://picsum.photos/seed/clothing3/400/300' },
        { id: 4, name: '保暖羊毛围巾', price: '89', originalPrice: '119', image: 'https://picsum.photos/seed/clothing4/400/300' },
        { id: 5, name: '透气纯棉衬衫', price: '129', originalPrice: '159', image: 'https://picsum.photos/seed/clothing5/400/300' },
        { id: 6, name: '防滑健步鞋', price: '159', originalPrice: '199', image: 'https://picsum.photos/seed/clothing6/400/300' }
      ],
      '医疗器械': [
        { id: 1, name: '智能电子血压计', price: '229', originalPrice: '269', image: 'https://picsum.photos/seed/medical1/400/300' },
        { id: 2, name: '家用血糖仪套装', price: '189', originalPrice: '229', image: 'https://picsum.photos/seed/medical2/400/300' },
        { id: 3, name: '颈椎腰部按摩器', price: '399', originalPrice: '459', image: 'https://picsum.photos/seed/medical3/400/300' },
        { id: 4, name: '轻便折叠轮椅', price: '599', originalPrice: '699', image: 'https://picsum.photos/seed/medical4/400/300' },
        { id: 5, name: '电子体温计', price: '79', originalPrice: '99', image: 'https://picsum.photos/seed/medical5/400/300' },
        { id: 6, name: '家用雾化器', price: '299', originalPrice: '359', image: 'https://picsum.photos/seed/medical6/400/300' },
      ],
      '营养保健': [
        {
          "id": 201,
          "name": "深海鱼油软胶囊",
          "price": "128.0",
          "originalPrice": "168.0",
          "image": "https://picsum.photos/seed/fish-oil/400/300"
        },
        {
          "id": 202,
          "name": "氨糖软骨素钙片",
          "price": "99.0",
          "originalPrice": "139.0",
          "image": "https://picsum.photos/seed/calcium-tab/400/300"
        },
        {
          "id": 203,
          "name": "复合维生素B族",
          "price": "59.9",
          "originalPrice": "89.9",
          "image": "https://picsum.photos/seed/vit-b/400/300"
        },
        {
          "id": 204,
          "name": "辅酶Q10护心胶囊",
          "price": "158.0",
          "originalPrice": "198.0",
          "image": "https://picsum.photos/seed/co-q10/400/300"
        },
        {
          "id": 205,
          "name": "益生菌冻干粉",
          "price": "69.0",
          "originalPrice": "99.0",
          "image": "https://picsum.photos/seed/probiotics/400/300"
        },
        {
          "id": 206,
          "name": "叶黄素护眼片",
          "price": "88.0",
          "originalPrice": "118.0",
          "image": "https://picsum.photos/seed/lutein/400/300"
        }
      ]
      // 其他分类产品...
    },

  },
  // 切换导航
  switchTab(e) {
    const index = e.currentTarget.dataset.index;
    this.setData({
      currentTab: index,
      showMoreNav: false // 切换时收起更多导航
    });
    // 可在此处根据 index 发起接口请求，获取对应分类的老年用品数据
    // 比如 if (index === 0) { this.getSeasonHotSeniorProducts() }
  },
  handleMore: function () {
    // 点击“查看更多”的逻辑，比如跳转到更多商品列表页面
    wx.navigateTo({
      url: '/pages/moreGoods/moreGoods'
    });
  },

  goTogooddetail(){
      wx.navigateTo({
        url: '/pages/gooddetail/gooddetail',
      })
  },

  // 跳转到商品详情页面
  goToGoodDetail(e) {
    const goods = e.currentTarget.dataset.goods;
    // 将商品信息编码后传递到详情页
    const goodsStr = encodeURIComponent(JSON.stringify(goods));
    wx.navigateTo({
      url: `/pages/gooddetail/gooddetail?goods=${goodsStr}`
    });
  },

  // 展开/收起更多导航
  toggleMoreNav() {
    this.setData({
      showMoreNav: !this.data.showMoreNav
    });
  },

   // 导航点击事件：可跳转页面或触发逻辑
   handleNavTap(e) {
    const type = e.currentTarget.dataset.type;
    switch(type) {
      case "hot":
        wx.navigateTo({ url: "/pages/hot/hot" });
        break;
      case "program":
        wx.navigateTo({ url: "/pages/program/program" });
        break;
      case "cart":
        wx.navigateTo({ url: "/pages/cart/cart" }); // 购物车通常用 switchTab
        break;
      case "merchant":
        wx.navigateTo({ url: "/pages/merchant/merchant" });
        break;
      default:
        break;
    }
  },

//   switchNav(e) {
//     const nav = e.currentTarget.dataset.nav;
//     this.setData({
//       currentNav: nav
//     });
//   },

//   goToDetail(e) {
//     const id = e.currentTarget.dataset.id;
//     wx.navigateTo({
//       url: `/pages/productDetail/productDetail?id=${id}`
//     });
//   },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})